package com.example.micro.netty.server.nio.channel;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.channels.FileChannel;

/**
 * 直接利用transferFrom/transferTo 复制channel 进行拷贝文件
 */
public class NIOFileCopyChannelDemo2 {

    public static void main(String[] args) throws IOException {

        FileInputStream fileInputStream = new FileInputStream("/Users/didi/IdeaProjects/file_img.JPG");
        FileOutputStream fileOutputStream = new FileOutputStream("/Users/didi/IdeaProjects/file_img_copy.JPG");

        FileChannel readChannel = fileInputStream.getChannel();
        FileChannel writeChannel = fileOutputStream.getChannel();

//        readChannel.transferTo(0, writeChannel.size(), writeChannel);
        writeChannel.transferFrom(readChannel, 0, readChannel.size());

        fileInputStream.close();
        fileOutputStream.close();

    }

}
